<?php

class MainMenu {

    private $ArMenus;

    public function __construct() {
        $this->ArMenus = array();
    }

    public function addMenu(Menu $Menu) {
        $this->ArMenus[ $Menu->getIDMenu() ] = $Menu;
    }

    public function addSubmenu(Submenu $Submenu) {
        foreach( $this->ArMenus as &$Menu ) {
            if( $Menu->getIDMenu() == $Submenu->getIDMenu() ) {
                $Menu->addSubmenu( $Submenu );
            }
        }
    }

    public function getArMenus() {
        return $this->ArMenus;
    }

    public function getMenuSelected() {
        $ArUrl = treatUrl();
        foreach( $this->ArMenus as $Menu ) {
            if( $Menu->has($ArUrl['Controller'], $ArUrl['Action']) ) {
                return $Menu;
            }
        }
        return false;
    }

}

?>
